package com.choudou5.solr.web.handler.sys;

import com.choudou5.solr.bean.common.PageResult;
import com.choudou5.solr.bean.common.SqlQueryBean;
import com.choudou5.solr.bean.sys.SysExceptionBean;
import com.choudou5.solr.framework.constants.ErrorResp;
import com.choudou5.solr.framework.util.PageJumpUtil;
import com.choudou5.solr.service.ServiceHelper;
import com.choudou5.solr.service.sys.SysExceptionService;
import com.choudou5.solr.utils.SqlQueryBuilder;
import com.choudou5.solr.web.handler.BaseHandler;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Name：系统异常 处理器
 * @Author：choudou5
 * @Date：2018-07-15
 */
public class SysExceptionHandler extends BaseHandler {

    private static SysExceptionService exceptionService = ServiceHelper.singleton(SysExceptionService.class);

    @Override
    public void execute(String method, HttpServletRequest req, HttpServletResponse resp) {
        logger.info("SysExceptionHandler method:{}", method);
        switch (method){
            case "pageList":
                pageList(req, resp);
                break;
            default:
                PageJumpUtil.errorOut(ErrorResp.Not_Found, req, resp);
                break;
        }
    }

    /**
     * 分页列表
     * @param req
     * @param resp
     */
    private void pageList(HttpServletRequest req, HttpServletResponse resp){
        SqlQueryBean sqlQueryBean = SqlQueryBuilder.buildWhereSql(req);
        sqlQueryBean.setOrderDefParam("create_time", "desc");
        PageResult<SysExceptionBean> pageResult = exceptionService.findPage(sqlQueryBean);
        req.setAttribute("pageResult", pageResult);
        PageJumpUtil.forward("sysExList", req, resp);
    }

}
